package com.shuda.business.crm.controller;

import com.shuda.business.crm.dto.CustomerFollowUpDTO;
import com.shuda.business.crm.dto.CustomerFollowUpQueryDTO;
import com.shuda.business.crm.service.CustomerFollowUpService;
import com.shuda.common.dto.PageDTO;
import com.shuda.common.utils.PageResult;
import com.shuda.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 客户跟进控制器
 */
@RestController
@RequestMapping("/api/crm/follow-ups")
@Tag(name = "客户跟进管理", description = "客户跟进管理相关接口")
@RequiredArgsConstructor
public class CustomerFollowUpController {

    private final CustomerFollowUpService customerFollowUpService;

    /**
     * 获取跟进记录分页列表
     */
    @GetMapping("/page")
    @Operation(summary = "获取跟进记录分页列表", description = "根据查询条件获取跟进记录分页列表")
    public R<PageResult<CustomerFollowUpDTO>> getFollowUpPage(
            @Parameter(description = "分页参数") PageDTO pageDTO,
            @Parameter(description = "查询条件") CustomerFollowUpQueryDTO queryDTO) {
        return R.ok(customerFollowUpService.getFollowUpPage(pageDTO, queryDTO));
    }

    /**
     * 获取跟进记录详情
     */
    @GetMapping("/{id}")
    @Operation(summary = "获取跟进记录详情", description = "根据ID获取跟进记录详情")
    public R<CustomerFollowUpDTO> getFollowUpById(@PathVariable Long id) {
        return R.ok(customerFollowUpService.getFollowUpById(id));
    }

    /**
     * 创建跟进记录
     */
    @PostMapping
    @Operation(summary = "创建跟进记录", description = "创建新的跟进记录")
    public R<CustomerFollowUpDTO> createFollowUp(@RequestBody CustomerFollowUpDTO followUpDTO) {
        return R.ok(customerFollowUpService.createFollowUp(followUpDTO));
    }

    /**
     * 更新跟进记录
     */
    @PutMapping("/{id}")
    @Operation(summary = "更新跟进记录", description = "更新跟进记录信息")
    public R<CustomerFollowUpDTO> updateFollowUp(@PathVariable Long id, @RequestBody CustomerFollowUpDTO followUpDTO) {
        return R.ok(customerFollowUpService.updateFollowUp(id, followUpDTO));
    }

    /**
     * 删除跟进记录
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "删除跟进记录", description = "删除跟进记录")
    public R<Boolean> deleteFollowUp(@PathVariable Long id) {
        return R.ok(customerFollowUpService.deleteFollowUp(id));
    }

    /**
     * 获取客户的跟进记录
     */
    @GetMapping("/customer/{customerId}")
    @Operation(summary = "获取客户跟进记录", description = "获取指定客户的所有跟进记录")
    public R<PageResult<CustomerFollowUpDTO>> getCustomerFollowUps(
            @Parameter(description = "分页参数") PageDTO pageDTO,
            @PathVariable Long customerId) {
        return R.ok(customerFollowUpService.getCustomerFollowUps(pageDTO, customerId));
    }

    /**
     * 获取我的跟进记录
     */
    @GetMapping("/my")
    @Operation(summary = "获取我的跟进记录", description = "获取当前用户的跟进记录")
    public R<PageResult<CustomerFollowUpDTO>> getMyFollowUps(
            @Parameter(description = "分页参数") PageDTO pageDTO) {
        return R.ok(customerFollowUpService.getMyFollowUps(pageDTO));
    }

    /**
     * 获取待跟进记录
     */
    @GetMapping("/pending")
    @Operation(summary = "获取待跟进记录", description = "获取待跟进的记录")
    public R<List<CustomerFollowUpDTO>> getPendingFollowUps() {
        return R.ok(customerFollowUpService.getPendingFollowUps());
    }
}